package com.proyecto.track.dao;

import java.util.ArrayList;

import org.hibernate.SessionFactory;

import com.proyecto.track.bo.TaskStatus;


public class TaskStatusDAOImp implements TaskStatusDAO {
	
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public Long createTaskStatus(TaskStatus taskStatus) {
		sessionFactory.getCurrentSession().save(taskStatus);
		return taskStatus.getId();
	}

	@Override
	public Long deleteTaskStatus(TaskStatus taskStatus) {
		Long id = taskStatus.getId();
		sessionFactory.getCurrentSession().delete(taskStatus);
		return id;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<TaskStatus> searchTaskStatus() {
		return  (ArrayList<TaskStatus>)sessionFactory.getCurrentSession().createQuery("from TaskStatus").list();
	}

	@Override
	public TaskStatus searchTaskStatus(Long id) {
		return (TaskStatus) sessionFactory.getCurrentSession().get(TaskStatus.class, id);
	}

}
